# f = open("text.txt",mode="w",encoding="utf-8")
# f.write("hello Python")
# f.close()

# f = open("text.txt", mode="r",encoding="utf-8")
# for line in f:
#     line = line.split()
#     print(line)

# 函数
# def name():
#     代码
#     ......

# def add(x, y):
#     print(x + y)
#     print(x - y)
#     print(x * y)
#     print(x / y)
#
#
# a = 10
# b = 20
# add(a, b)

# 默认参数
# def fun(name, age, height, country="CN"):
#     print(name)
#     print(age)
#     print(height)
#     print(country)


# fun("zhangsan", 20, 172)
# fun("zhangsan", 20, 172, "US")
# # 默认参数放必须放在最后，如果不填写，直接是默认值

# 调用
# def fun(name, age, height, country="CN"):
#     print(name)
#     print(age)
#     print(height)
#     print(country)
#
#
# fun( age=22, name="lisi", height=170 )
# 只要是开始手动排序后面都必须手动排序
# 位置参数 > 关键参数

# def fun(name, age, height, *args, **kwargs):
#     print(name)
#     print(age)
#     print(height)
#     print(args)
#     print(kwargs)
#
#
# fun("zhangsan", "22", 170, "lisi", "I love Python", name1=["zhangsan", 18])
#
# # def fun2(*args):
# #     print(args)
# #
# # fun2("zhangsan","lisi","wangwu")

# def fun(name, age, height, *args, **kwargs):
#     print(name)
#     print(age)
#     print(height)
#     print(args)
#     print(kwargs)
#     if age > 20:
#         return age,height,name
#
#
# ret = fun("lisi", 23, 167)
# print(ret)


# a = 10
#
#
# def add(x):
#     x += 1
#
#
# add(a)
# print(a)
# def change(list3):
#     list3[1] = "coco"
#
#
# list1 = ["zhangsan", "lisi", "wangwu", "zhaoliu"]
# list2 = list1
# change(list1)
# print(list1)
# print(list2)
# list1[1] = "coco"
# print(list1)
# print(list2)

# for i in range(0,11):
#     print(i,end="")

# ret = sum(range(11))
# print(ret)

# print(round(3.6))


# 函数
# 函数的定义
# def add(x,y):
#     代码:

# def fun(x):
#     if x > 10:
#         return "Yes"
#     else:
#         return "No"
#
#
# num = int(input("请输入数字："))  # input函数的返回值时字符类型
# ret = fun(num)
# print(ret)


# 默认参数
# 默认参数必须放在最后
# def information (name,age,height,country="CN"):
#     print("---学生信息情况---")
#     print(name)
#     print(age)
#     print(height)
#     print(country)
#
#
# information("zhangsan",23, 170,"CN")
# information("lisi",22, 169,"US")
# 默认参数必须放在最后
# def information(name, age, country="CN", height):
#     print("---学生信息情况---")
#     print(name)
#     print(age)
#     print(height)
#     print(country)
#
#
# information("zhangsan", 23, "CN",)
# information("lisi", 22, 169, "US")

# 关键参数
# def peo(name, age, phone, country="CN"):
#     print(name)
#     print(age)
#     print(phone)
#     print(country)
#
#
# peo("zhangsan", phone="123456789", age=23, country="US")# 只要一个开始后就都需要关键命名了

# def Stu(name, age, phone, *args):
#     print(name)
#     print(age)
#     print(phone)
#     print(args)
#
#
# Stu('John', 21, '222333444555', "I love Python", "I am 20 years old")
# *args  -->元组

# **kwargs

# def people(name, age, phone, **kwargs):
#     print(name)
#     print(age)
#     print(phone)
#     print(kwargs)
#
#
# people('John', 25, phone='123456', name1="zhangsan", age1="19", phone1="7654321")

# 元组
# tuple1 = (1, 2, 3, 4, 5, 6)
# print(tuple1)
# tuple1 = ()
# print(tuple1)
# tuple1 = ("hello")
# print(type(tuple1)) # str
# tuple2 = ("Python",)
# print(type(tuple2))
# 元组只用一个数据的时候要加上，否则为字符
# tuple1 = (1, 2, 3, 4, 5, 6, 7, 8, 9)
# print(tuple1[4])
# print(tuple1[5])
# print(tuple1[6])
# 下标访问和列表相同


# tuple1 = (range(1, 11))
# print(tuple1)
# ret = list(range(11))
# print(ret)
# list1 = range(11)
# list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# print(list2)

# tuple1 = range(0,11)
# print(tuple1)
# ret = tuple(range(0,11))
# print(ret)

# result = tuple(range(11))
# print(result)
# for i in result: # 可迭代
#     print(i)

# 元组不可以被修改
# ret = tuple(range(11))
# # print(ret)
# ret[5] = 100

# index and count and len
# ret = tuple(range(11))
# result = len(ret)
# print(result)
# ret = len("zhangsan")
# print(ret)
# tuple1 = (1, 1, 2, 3, 4, 5, 6, 8, 3, 5, 1)
# print(tuple1.count(1))
# tuple1 = (1, 1, 2, 3, 4, 5, 6, 8, 3, 5, 1)
# ret = tuple1.index(2)
# print(ret)

# list1 = ["zhangsan","lisi","wangwu"]
# list1[1] = "coco"
# for i in list1:
#     print(i)

# return
# def people(name, age, phone_number, *args, **kwargs):
#     print(name)
#     print(age)
#     print(phone_number)
#     print(args, kwargs)
#     if age > 18:
#         return "已经成年了"
#     else:
#         return "未成年"
#
#
# ret = people('John', 17, '12345')
# print(ret)


# # 全局变量和局部变量
# name = "zhangsan"  # 全局变量
#
#
# def change_name(name):
#     print("要准备修改名字了！")
#     name1 = name  # 局部变量
#     print(name1)
#
#
# change_name("coco")
# print(name)


# 列表，字典，集合
# list1 = ["zhangsan", "lisi", "wangwu"]
#
#
# def change_name(change):
#     list1.append(change)
#
#
# change_name("coco")
# for i in list1:
#     print(i)

# dic = dict(name="zhangsan", age=22, phone=123456789)
#
# def change_information(change_name):
#     dic["name"] = change_name
#
#
# change_information("coco")
# print(dic)

# dic = \
#     {
#         "name": "zhangsan",
#         "age": 18
#     }
# dic["name"] = "coco"
# print(dic)

# 列表 ， 字典  ，集合的存储方式不同
#
# list1 = list(range(11))
# list2 = list1
#
#
# def change_list():
#     list1.clear()
#
# print(list1)
# print(list2)
# change_list()
# print(list1)
# print(list2)

# name = "zhangsan"
#
#
# def change_name(name):
#     global name1
#     name1 = name
#  使用global定义全局变量
#
# change_name("coco")
# print(name1)
# print(name)

# def change_name():
#     global name1
#     name1 = "coco"
#
#
# change_name()
# print(name1)


# 常用函数
# abs --- absolute(绝对值)
# num = -100
# print(abs(num))


# all函数  --- 有假为假
# str1 = "zhangsan"
# for i in str1:
#     print(i)

# S = "zhangsan"
# print(all(S))
# tuple1 = tuple(range(1,11))
# print(tuple1)
# print(all(tuple1))
#

# any函数  --- 有真为真
# list1 = list(range(11))
# print(any(list1))

# chr函数  -- ASCII码转字符
# print(chr(97))

# bool函数

# print(bool("a"))
# dic = dict()
# print(dic)
#
#
# dir函数  --- 显示所以的变量
# name = "zhangsan"
# age = 18
# print(dir())

# help(filter)


# id函数  --- 返回变量地址

# a = 10
# b = 20
# print(id(a))
# print(id(b))

# input函数 --- 输入
# # int（） --- 强制转换
# num = int(input("please enter a number"))
# print(num)

# len函数  --- 万能求长度
# list1 = list(range(11))
# ret = len(list1)
# print(ret)
#
# max and min函数
# tuple1 = tuple(range(11))
# ret1 = max(tuple1)
# ret2 = min(tuple1)
# print(ret1)
# print(ret2)

# # ord函数
# print(ord("a"))


# round函数
# print(round(3.1415,1))
# print(round(3.6515,1))


# sum函数
# list1 = list(range(11))
# ret = sum(list1)
# print(ret)

# S = "zhangsan"
# ret = sum(S)
# print(ret)
#

# str函数 --- 转化成str类型
# dic = dict()
# print(type(str(dic)))


# zip函数
# list1 = ["zhnagsan", "lisi", "wangwu"]
# list2 = [1, 2, 3]
# ret = zip(list1, list2)
# for item in ret:
#     print(item)

# map函数
# def add(x):
#     return x+10
#
#
# ret = map(add,range(11))
# for i in ret:
#     print(i)
# map(一个函数，可迭代对象)
